//
//  ToolCityViewController.m
//  TravelEveryDay
//
//  Created by 路洪宇 on 15/10/27.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "ToolCityViewController.h"
#import "ToolDetailViewController.h"
#import "BaseHeader.h"
@interface ToolCityViewController ()
@property(nonatomic,retain)NSString *currency_codeStr;
@end

@implementation ToolCityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    [self getLocationData];

    [self setUpTitleView];
}

-(void)setUpTitleView
{
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    [titleView setBackgroundColor:TITLECOLOR];
    [self.view addSubview:titleView];
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:@"play-jiantouzuo.png"] forState:UIControlStateNormal];
    [backButton setFrame:CGRectMake(10, 30, 22, 22)];
    [backButton addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];
    [titleView addSubview:backButton];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-100, 25, 200, 30)];
    [title setText:self.tempModel.name_zh_cn];
    [title setTextColor:[UIColor whiteColor]];
    title.font = [UIFont systemFontOfSize:19.];
    title.textAlignment = NSTextAlignmentCenter;
    [titleView addSubview:title];
    
    
    [self.view addSubview:titleView];
    
}

- (void)getLocationData
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://chanyouji.com/api/wiki/destinations/infos/%@.json?page=1",self.tempModel.mId];
    [AFNDataBlock string:urlStr AFNData:^(id block) {
        
        _currency_codeStr = [block objectForKey:@"currency_code"];

        NSLog(@"%@",_currency_codeStr);
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 250)];
        [imageView sd_setImageWithURL:[NSURL URLWithString:self.tempModel.image_url]];
        [self.view addSubview:imageView];
        
        //实现模糊效果
        UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
        visualEffectView.frame = CGRectMake(0, 64, SCREEN_WIDTH, 250);
        visualEffectView.alpha = 0.75;
        [self.view addSubview:visualEffectView];
        
        UILabel *minTemp = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/4-100, imageView.frame.size.height+74, 200, 80)];
        minTemp.text = [NSString stringWithFormat:@"%@℃",[block objectForKey:@"temp_min"]];
        minTemp.textAlignment = NSTextAlignmentCenter;
        minTemp.font = [UIFont systemFontOfSize:40];
        minTemp.textColor = TITLECOLOR;
        [self.view addSubview:minTemp];
        
        UILabel *maxTemp = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/4*3-100, imageView.frame.size.height+74, 200, 80)];
        maxTemp.text = [NSString stringWithFormat:@"%@℃",[block objectForKey:@"temp_max"]];
        maxTemp.textAlignment = NSTextAlignmentCenter;
        maxTemp.font = [UIFont systemFontOfSize:40];
        maxTemp.textColor = [UIColor redColor];
        [self.view addSubview:maxTemp];
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-20, imageView.frame.size.height+74+maxTemp.frame.size.height/2, 40, 1)];
        lineView.backgroundColor = [UIColor lightGrayColor];
        [self.view addSubview:lineView];
        
        UILabel *timeCity = [[UILabel alloc] initWithFrame:CGRectMake(0, maxTemp.frame.size.height+maxTemp.frame.origin.y+10, SCREEN_WIDTH, 30)];
        timeCity.text = [NSString stringWithFormat:@"当地时间:%@",[block objectForKey:@"current_time"]];
        timeCity.textAlignment = NSTextAlignmentCenter;
        timeCity.font = [UIFont systemFontOfSize:15];
        timeCity.textColor = [UIColor blackColor];
        [self.view addSubview:timeCity];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(SCREEN_WIDTH/2-50,timeCity.frame.size.height+timeCity.frame.origin.y,100, 150);
        [button setImage:[UIImage imageNamed:@"ToolboxItem3_Normal@2x.png"] forState:UIControlStateNormal];
        button.imageEdgeInsets = UIEdgeInsetsMake(5,13,10,20);
        [button setTitle:@"实时汇率" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        button.titleEdgeInsets = UIEdgeInsetsMake(65,-65, 0, 0);
        [button addTarget:self action:@selector(ButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
        
    }];
    
}

-(void)ButtonClick
{
    ToolDetailViewController *detailVC = [[ToolDetailViewController alloc] init];
    detailVC.cityStr = _currency_codeStr;
    [self.navigationController pushViewController:detailVC animated:YES];
}

-(void)leftClick
{
#pragma mark- 返回指定页面
    UIViewController *vc =[self.navigationController.viewControllers objectAtIndex:1];
    [self.navigationController popToViewController:vc animated:YES];
    self.tabBarController.tabBar.hidden = NO;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
